home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Grand Slam
/
GrandSlam volume 1.iso
/
030
/
grasputl.arj
/
GL-MAKE.C
next >
Wrap
C/C++ Source or Header
|
1991-03-12
|
3KB
|
125 lines
#include <stdio.h>
#include <stdlib.h>
/*
From zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!cunixf.cc.columbia.edu!
cs.columbia.edu!cooper Tue Jan 29 22:07:41 EST 1991
oops, forgot something important. here it is:
*/
/* Directory entry in GL file */
#if 0
struct s_entry {
long bignum;
char name[13];
}
#endif
/* We don't use it, since some C's make it more than 17 bytes... */
main()
{
short top; /* size of directory */
unsigned char *entry; /* list of directory entries */
char glfile[100], listfile[100];
FILE *fp; /* list of files to join */
FILE *newfp; /* the created gl file */
FILE *oldfp; /* File we're currently adding */
int num_ents = 0; /* number of files to assemble */
int i;
short bsize; /* Size of buffer (see below) */
long rsize; /* Size of current file */
char buff[1024];
long sofar; /* Number of bytes written so far */
/* For referencing fileds in entry table: */
long *bignum;
unsigned char *name;
/* Open required files */
printf("GL file to create? "); scanf("%s",glfile);
printf("list file? "); scanf("%s",listfile);
fp = fopen(listfile,"r");
if (fp == NULL)
{
printf("couldn't open list file %s\n", listfile);
exit(-1);
}
newfp = fopen(glfile,"w");
if (newfp == NULL)
{
fclose(fp);
printf("couldn't create GL file %s\n", glfile);
exit(-1);
}
/* Just count the number of files, to make directory */
while(1)
{
i = fscanf(fp,"%s",buff);
if (i <= 0 || buff[0] == 0)
break;
num_ents++;
}
rewind(fp);
top = (num_ents+1) * 17;
/* Allocate space for directory */
entry = (unsigned char *)calloc(top, 1);
/* Write directory size... */
fwrite(&top, 2, 1, newfp);
/* But leave blank until we get all info */
fseek(newfp, (long)top, 1);
sofar = top+2;
/* Process each file */
bignum = (long *)entry;
name = entry+4;
for (i = 0; i < num_ents; i++, name+=17, bignum = (long *)(name-4))
{
fscanf(fp,"%s",buff); /* read file naame */
oldfp = fopen(buff,"r"); /* open the file */
if (oldfp == NULL)
{
fclose(fp);
fclose(newfp);
free(name);
free(bignum);
printf("Can't read file %s : aborting \n", buff);
exit(-1);
}
/* Make directory entry */
strcpy(name, buff);
*bignum = sofar;
/* Copy file to gl file, one buffer at a time, */
/* Accumulating size */
rsize = 0;
while(1)
{
bsize = fread(buff, 1, sizeof(buff), oldfp);
fwrite(buff, bsize, 1, newfp);
rsize += bsize;
if (bsize < sizeof(buff))
break;
}
sofar += rsize;
fclose(oldfp);
}
fclose(fp);
/* Now write directory */
fseek(newfp, 2L, 0);
fwrite(entry, top, 1, newfp);
fclose(newfp);
free(entry);
}